package com.own.business.log.operation.persistence.controller.manage;

import com.own.aop.login.LoginIgnore;
import com.own.aop.permission.PermissionModule;
import com.own.business.log.operation.persistence.business.service.LogOperationElasticService;
import com.own.business.log.operation.persistence.common.constant.ConstantModule;
import com.own.business.log.operation.persistence.entity.query.LogOperationQuery;
import com.own.business.log.operation.persistence.entity.vo.LogOperationElasticVo;
import com.own.component.common.base.controller.BaseController;
import com.own.component.common.model.PageModel;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import com.own.component.log.operation.aop.LogOperationAop;
import com.own.constant.ConstantApiPrefix;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * ManageLogOperationPersistenceController
 *
 * @author chenxueli
 * @date 2023-08-03 09:30:47
 */
@Tag(name = "操作日志持久化" + ConstantBeanSuffix.MANAGE_CLIENT + ConstantBeanSuffix.CONTROLLER)
@RestController
@PermissionModule(ConstantModule.LOG_OPERATION_MANAGE)
@RequestMapping(ConstantApiPrefix.BASE_API_V1_PREFIX + ConstantApiPrefix.MANAGE_CLIENT + "log/operation")
public class ManageLogOperationPersistenceController extends BaseController {

    @Resource
    private LogOperationElasticService logOperationElasticService;

    @LogOperationAop(level = 10)
    @Operation(summary = "分页查询信息")
    @PostMapping("/page")
    public ResultModel<PageModel<LogOperationElasticVo>> page(
            @RequestBody LogOperationQuery query
    ) {
        var pageModel = logOperationElasticService.page(query);
        return R.success(pageModel);
    }

    @LogOperationAop(level = 10)
    @Operation(summary = "根据操作日志id查询信息")
    @GetMapping("/{id}")
    public ResultModel<LogOperationElasticVo> getById(
            @Parameter(description = "操作日志id", required = true) @PathVariable String id
    ) {
        var vo = logOperationElasticService.getById(id);
        return R.success(vo);
    }

    @LoginIgnore
    @LogOperationAop(level = 10)
    @Operation(summary = "根据链路id查询信息")
    @GetMapping("/trace/{traceId}")
    public ResultModel<LogOperationElasticVo> getByTraceId(
            @Parameter(description = "链路id", required = true) @PathVariable String traceId
    ) {
        var vo = logOperationElasticService.getByTraceId(traceId);
        return R.success(vo);
    }

}
